package io.flutter.plugins;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Process;
import android.util.Log;

import com.sgcc.ydfirebasesdk.YDFirebaseSDK;

import java.util.List;

import io.flutter.app.FlutterApplication;

/**
 * package : zhiyi.com.teacher_app
 * author : zhiyi
 * date : 12/10/2020 2:10 PM
 * project : android
 * description :
 */
public class MyApp extends FlutterApplication {

    private static Context context;
    @Override
    public void onCreate() {
        super.onCreate();
        context =getApplicationContext();
        // 注册push服务，注册成功后会发送广播
        // 可以从DemoMessageReceiver的onCommandResult方法中MiPushCommandMessage对象参数中获取注册信息
        if (shouldInit()) {
            if (!getSystemModel().equals("HUAWEI")){
                Log.d("手机型号: ",getSystemModel());
                YDFirebaseSDK.Companion.getSingleInstance().registerNotification(this);
            }else {
//                PushManager.create().register(this);
            }

        }

    }
    public static Context getContext() {
        return  context;
    }
    private boolean shouldInit() {
        ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
        List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
        String mainProcessName = getPackageName();
        int myPid = Process.myPid();
        for (ActivityManager.RunningAppProcessInfo info : processInfos) {
            if (info.pid == myPid && mainProcessName.equals(info.processName)) {
                return true;
            }
        }
        return false;
    }
    /**
     * 获取手机厂商
     */
    public static String getSystemModel() {
        return android.os.Build.MANUFACTURER;
    }

}
